x11: Fix damage tracking hack
authorMatthias Clasen <mclasen@redhat.com>
Fri, 8 Jan 2016 18:44:36 +0000 (13:44 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 8 Jan 2016 18:44:36 +0000 (13:44 -0500)
We are setting mime data with a destroy notify on the cairo
surface to get notified when cairo registers damage for the
surface (in that case, it clears the mime data, calling the
destroy notify). Unfortunately, the destroy notify is also
called when we remove the mime data ourselves, which was
not intentional.

Use a flag in the window impl struct to ignore the callback
when we are clearing the hook.

gdk/x11/gdkwindow-x11.c
gdk/x11/gdkwindow-x11.h

index 9f189ad6265845b57538a89bbd3a85863ae7b80d..6106b28d1830c81c50eadd7952968e1b08e0fe3d 100644 (file)
@@ -250,8 +250,10 @@ static void
 on_surface_changed (void *data)
 {
   GdkWindow *window = data;
+  GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
 
-  window_pre_damage (window);
+  if (impl->tracking_damage)
+    window_pre_damage (window);
 }
 
 /* We want to know when cairo drawing causes damage to the window,
@@ -269,12 +271,15 @@ hook_surface_changed (GdkWindow *window)
   GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
 
   if (impl->cairo_surface)
-    cairo_surface_set_mime_data (impl->cairo_surface,
-                                 "x-gdk/change-notify",
-                                 (unsigned char *)"X",
-                                 1,
-                                 on_surface_changed,
-                                 window);
+    {
+      cairo_surface_set_mime_data (impl->cairo_surface,
+                                   "x-gdk/change-notify",
+                                   (unsigned char *)"X",
+                                   1,
+                                   on_surface_changed,
+                                   window);
+      impl->tracking_damage = 1;
+    }
 }
 
 static void
@@ -283,10 +288,13 @@ unhook_surface_changed (GdkWindow *window)
   GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
 
   if (impl->cairo_surface)
-    cairo_surface_set_mime_data (impl->cairo_surface,
-                                 "x-gdk/change-notify",
-                                 NULL, 0,
-                                 NULL, NULL);
+    {
+      impl->tracking_damage = 0;
+      cairo_surface_set_mime_data (impl->cairo_surface,
+                                   "x-gdk/change-notify",
+                                   NULL, 0,
+                                   NULL, NULL);
+    }
 }
 
 static void
index 2bc2417d8b64e1ca9040584cbe8f71339fb55c6a..ed0cbb6cf38758ad93d5592a0a3dc41bfd4b2e44 100644 (file)
@@ -73,6 +73,7 @@ struct _GdkWindowImplX11
   guint override_redirect : 1;
   guint frame_clock_connected : 1;
   guint frame_sync_enabled : 1;
+  guint tracking_damage: 1;
 
   gint window_scale;